package pkg

import (
	"log"

	"dubbo-go-app/pkg/config"
	activity "dubbo-go-app/pkg/internal/controller/v1"
	"dubbo-go-app/pkg/internal/data/v1/db"
	"dubbo-go-app/pkg/internal/service/v1"

	server "dubbo.apache.org/dubbo-go/v3/config"
	start "dubbo.apache.org/dubbo-go/v3/config"
	_ "dubbo.apache.org/dubbo-go/v3/imports"
)

func NewTriServer() {
	//初始化所需要的配置信息 yaml映射struct
	cfg := config.New()
	//单例模式启动mysql连接池 并初始化data层(持有gorm), 如果data层是tri远程调用 则不需要持有
	dataFactory, err := db.GetDBFactoryOr(cfg.MySQLOptions)
	if err != nil {
		log.Fatal(err.Error())
	}
	//初始化service层(持有data层)
	srvFactory := v1.NewService(dataFactory)
	//初始化controller层(持有service层)
	Server := activity.NewActivityServer(srvFactory)
	//设置dubbogo中的server
	start.SetProviderService(Server)

	if err = server.Load(); err != nil {
		panic(err)
	}
	select {}
}
